/*
 * SpeculationTask.h
 *
 *  Created on: Mar 17, 2012
 *      Author: user
 */

#ifndef SPECULATIONTASK_H_
#define SPECULATIONTASK_H_

#include <string>
#include <time.h>
#include <sys/time.h>

using namespace std;

enum SpeculationStatus
{
	SPS_WAITING = 0,
	SPS_RUNNING,
	SPS_COMPLETED
};

class SpeculationTask
{
public:
	SpeculationTask(string s);
	virtual ~SpeculationTask();
	virtual void execute() = 0;
	virtual void commit();

	void sendCommandToMaster( int command );
	void recvCommandFromMaster( int *command );

	void sendToMaster( int size, const void *data );
	void recvFromMaster( int size, void *data );

	string &getSignature() { return m_signature; }
	SpeculationStatus getStatus() { return m_status; }
	void setStatus(SpeculationStatus status) { m_status = status; }

	pid_t	getProcessId() { return m_processId; }
	void	setProcessId(pid_t pid) { m_processId = pid; }

	int m_socket;
	timeval m_timeStamp;

protected:

	string m_signature;
	SpeculationStatus m_status;

	pid_t	m_processId;
};

typedef	SpeculationTask*(*SpeculationGeneratorFunction)(void);

#endif /* SPECULATIONTASK_H_ */
